package exam.demo;

import java.io.*;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/4/8 9:27
 * @since JDK 1.8
 */
public class Test implements Cloneable, Serializable {

    private Integer index;

    private String msg;

    public Test() {
    }

    public Test(Integer index, String msg) {
        this.index = index;
        this.msg = msg;
    }

    public Integer getIndex() {
        return index;
    }

    public void setIndex(Integer index) {
        this.index = index;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }


    private Object deepClone() throws IOException,
            OptionalDataException,ClassNotFoundException{//将对象写到流里
        ByteArrayOutputStream bo=new ByteArrayOutputStream();
        ObjectOutputStream oo=new ObjectOutputStream(bo);
        oo.writeObject(this);//从流里读出来
        ByteArrayInputStream bi=new ByteArrayInputStream(bo.toByteArray());
        ObjectInputStream oi=new ObjectInputStream(bi);
        return(oi.readObject());
    }


    @Override
    public Object clone(){
        try {
            return super.clone();
        }catch ( CloneNotSupportedException e){
            e.printStackTrace();
        }
        return null;
    }



    @Override
    public String toString() {
        return "Test{" +
                "index=" + index +
                ", msg='" + msg + '\'' +
                '}';
    }
}
